/**
 * 
 */
package org.lookouster.nextAgadir.pointageBureau.bases;

import java.sql.SQLException;
import java.util.Collection;
import java.util.Iterator;
import org.lookouster.nextAgadir.pointageBureau.*;
import org.lookouster.nextAgadir.pointageBureau.dbDESC.Tables;
import org.lookouster.nextAgadir.pointageBureau.outils.BDConnect;
import org.lookouster.nextAgadir.pointageBureau.outils.Commons;
import org.lookouster.nextAgadir.pointageBureau.outils.functions;

/**
 * @author Lookouster
 *
 */
public class Controleur extends Employe {

	
	public Controleur(String mat, String cin, String nom,
			String pren, int age, String phone, String det)
	{
		super(mat, nom, pren,cin,  age, phone, Commons.DB_TYP_CTL,det);
		//Nothing else!!
	}
	
	public Controleur(Employe emp)
	{
		super(emp.getMatriculeEmploye(),
			  emp.getNomEmploye(),
			  emp.getPrenomEmploye(),
			  emp.getCinEmploye(),
			  emp.getAgeEmploye(),
			  emp.getTelEmploye(),
			  Commons.DB_TYP_OUVR,
			  emp.getDetailEmploye());
		this.setIdEmploye(emp.getIdEmploye());
	}
	/**
 *
 */
private Collection<Controle> controle;

/**
 * Getter of the property <tt>controle</tt>
 *
 * @return Returns the controle.
 * 
 */
public Collection<Controle> getControle()
{
	return controle;
}
 
/**
 * Returns an iterator over the elements in this collection. 
 *
 * @return an <tt>Iterator</tt> over the elements in this collection
 * @see	java.util.Collection#iterator()
 * 
 */
public Iterator<Controle> controleIterator(){
	return controle.iterator();
}

/**
 * Returns <tt>true</tt> if this collection contains no elements.
 *
 * @return <tt>true</tt> if this collection contains no elements
 * @see	java.util.Collection#isEmpty()
 *
 */
public boolean isControleEmpty(){
	return controle.isEmpty();
}

/**
 * Returns <tt>true</tt> if this collection contains the specified element. 
 *
 * @param element whose presence in this collection is to be tested.
 * @see	java.util.Collection#contains(Object)
 *
 */
public boolean containsControle(Controle controle){
	return this.controle.contains(controle);
}

/**
 * Returns <tt>true</tt> if this collection contains all of the elements
 * in the specified collection.
 *
 * @param elements collection to be checked for containment in this collection.
 * @see	java.util.Collection#containsAll(Collection)
 *
 */
public boolean containsAllControle(Collection<Controle> controle){
	return this.controle.containsAll(controle);
}

/**
 * Returns the number of elements in this collection.
 *
 * @return the number of elements in this collection
 * @see	java.util.Collection#size()
 *
 */
public int controleSize(){
	return controle.size();
}

/**
 * Returns all elements of this collection in an array.
 *
 * @return an array containing all of the elements in this collection
 * @see	java.util.Collection#toArray()
 *
 */
public Controle[] controleToArray(){
	return controle.toArray(new Controle[controle.size()]);
}


/**
 * Ensures that this collection contains the specified element (optional
 * operation). 
 *
 * @param element whose presence in this collection is to be ensured.
 * @see	java.util.Collection#add(Object)
 *
 */
public boolean addControle(Controle controle){
	return this.controle.add(controle);
}

/**
 * Setter of the property <tt>controle</tt>
 *
 * @param controle the controle to set.
 *
 */
public void setControle(Collection<Controle> controle){
	this.controle = controle;
}

/**
 * Removes a single instance of the specified element from this
 * collection, if it is present (optional operation).
 *
 * @param element to be removed from this collection, if present.
 * @see	java.util.Collection#add(Object)
 *
 */
public boolean removeControle(Controle controle){
	return this.controle.remove(controle);
}

/**
 * Removes all of the elements from this collection (optional operation).
 *
 * @see	java.util.Collection#clear()
 *
 */
public void clearControle(){
	this.controle.clear();
}


public void saveDB(BDConnect bdc){
	
	this.setIdEmploye(Employe.saveDB(bdc, this.getMatriculeEmploye(), this.getNomEmploye(),
			this.getPrenomEmploye(), this.getCinEmploye(), this.getAgeEmploye(),
			this.getTelEmploye(),Commons.DB_TYP_CTL,this.getDetailEmploye()));
	
	String requestItem;
	
	//Enregistrement dans la table Controleur
		requestItem="INSERT INTO "+Tables.DB_TABLE_CLEUR +" values('"+
		this.getIdEmploye()+"')";
		try {
			bdc.update(requestItem);
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			functions.affiche(Commons.TAG+Commons.DB_INSERT_FAIL+" Controleur");
		}
	
	
}
/**
 * Update the "controleur" referenced by matricule, set it to this object
 * @param bdc
 * @param matricule
 */

	public void updateDB(BDConnect bdc, String newMat,String nom, String prenom,
			String cin, int age, String phone, int type, String det)
	{
		Employe.update(bdc, this.getIdEmploye(), newMat, nom, prenom, cin, age, phone, type, det);
		
		//NOthing else for now!!
	}



}
